<?php
/**
 * Created by PhpStorm.
 * User: crstu
 * Date: 2016/6/14
 * Time: 16:32
 */

namespace common\models;

use yii\helpers\ArrayHelper;

class CommonModel
{

    /**
     * 根据某个模型返回简单数组对，一般用于模板中的下拉选择框
     * @param $model
     * @param $key
     * @param $value
     * @param string $where
     * @return array
     */
    public static function getSimpleList($model, $key, $value, $where = '')
    {
        $query = $model->find()->select([$key, $value]);
        if(!empty($where)){
            $query->where($where);
        }
        $all = $query->asArray()->all();
        if(!empty($all)){
            return ArrayHelper::map($all, $key, $value);
        }else{
            return [];
        }
    }

}